extends CanvasLayer

var bar_red = preload("res://assets/ui/barHorizontal_red_mid 200.png")
var bar_yellow = preload("res://assets/ui/barHorizontal_yellow_mid 200.png")
var bar_green = preload("res://assets/ui/barHorizontal_green_mid 200.png")
var bar_texture

onready var health_bar = $Margin/VBoxContainer/Container/HealthBar
onready var ammo_bar = $Margin/VBoxContainer/Container2/AmmoBar

func update_healthbar(value):
	bar_texture = bar_green
	if value < 30:
		bar_texture = bar_red
	elif value < 60:
		bar_texture = bar_yellow
		
	health_bar.texture_progress = bar_texture
	health_bar.get_node("Tween").interpolate_property(health_bar, "value", health_bar.value, value, 0.2, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
	health_bar.get_node("Tween").start()
	$AnimationPlayer.play("healthbar_flash")
	
func update_ammobar(value):
	ammo_bar.get_node("Tween").interpolate_property(ammo_bar, "value", ammo_bar.value, value, 0.4, Tween.TRANS_BOUNCE, Tween.EASE_OUT)
	ammo_bar.get_node("Tween").start()


func _on_AnimationPlayer_animation_finished(anim_name):
	if anim_name == "healthbar_flash":
		health_bar.texture_progress = bar_texture
